package com.leoren.blog.controller;

import com.alibaba.druid.filter.AutoLoad;
import com.leoren.blog.common.Result;
import com.leoren.blog.service.FollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Leoren
 * @since 2023年11月24日
 */
@Api(tags = "关注表")
@RestController
@RequestMapping("/follow")
@Slf4j
public class FollowController {

    @Autowired
    private FollowService followService;


    @ApiOperation(value = "用户关注", notes = "关注操作")
    @GetMapping("/follow")
    public Result<Object> follow(int followerId, int followeeId){

        int count = followService.follow(followerId, followeeId);
        if(count > 0){
            return Result.OK("关注成功");
        }else if(count < 0){
            return Result.error("已经关注了！");
        }
        return Result.error("关注失败");
    }

    @ApiOperation(value = "用户取消关注", notes = "取消关注操作")
    @GetMapping("/unFollow")
    public Result<Object> unFollow(int followerId, int followeeId){
        int count = followService.unFollow(followerId, followeeId);
        if(count > 0){
            return Result.OK("取消关注成功");
        }else if(count < 0){
            return Result.error("还未关注！");
        }
        return Result.error("取消关注失败");
    }

}
